package com.hzvdvmc.autosale.util;

import com.google.gson.Gson;

/**
 * Title: GsonUtils <br>
 * Description: Gson工具<br>
 * Copyright (c) 传化物流版权所有 2017 <br>
 * Created DateTime: 2017-3-21 16:02
 * Created by Wentao.Shi.
 */
public class GsonUtils {
    private static Gson gson = null;
    static {
        if (gson == null) {
            gson = new Gson();
        }
    }
    /**
     * 转成json
     *
     * @param object
     * @return
     */
    public static String GsonString(Object object) {
        String gsonString = null;
        if (gson != null) {
            gsonString = gson.toJson(object);
        }
        return gsonString;
    }

    /**
     * 转成bean
     *
     * @param gsonString
     * @param cls
     * @return
     */
    public static <T> T GsonToBean(String gsonString, Class<T> cls) {
        T t = null;
        if (gson != null) {
            t = gson.fromJson(gsonString, cls);
        }
        return t;
    }

}
